<?php 

namespace app\common;

require_once __DIR__.'/Log.php';
use \GatewayWorker\Lib\Gateway; 
use app\common\Log;


/**
 * 基类
 */
class Base 
{

    protected $log = null;
    protected $api = null;


	function __construct()
	{
        $this->log = new Log();
	}

    /**
     * 日志
     */
    public function log($data='',$level='normal')
    {
        $this->log->log($data,$level);
    }

    public function save_api($value='')
    {
        $this->api = $value;
    }


	/**
     * 返回信息
     * 
     * @param unknown $res
     * 
     * @return \think\response\Json
     */
    public function outMessage($code = 0,$message = "request success",$data = array(),$status = 'success',$count = 0)
    {   
        $data = [
            'api' => $this->api?$this->api:'error',
            'code' => $code,
            'message' => $message,
            'status' => $status,
            'type' => $_SESSION['returnType'],
            'count' => $count,
            'data' => $data
        ];
        if($data){
            $this->log('向用户发送数据');
            $this->log($data);
            return Gateway::sendToCurrentClient(json_encode($data)."\r\n");
        }else{
            abort(404);
        }
    }





}


